<template>
  <div class="container">
    <div class="shotbox" style="height: 500px;padding-top: 100px;">
      <h1 style="text-align: center;margin-bottom: 50px;">证书查询</h1>
      <el-row type="flex" justify="center">
        <el-col :span="8">
          <el-form :model="ruleForm" status-icon label-width="100px" class="demo-ruleForm">
            <el-form-item label="身份证" prop="idCard">
              <el-input type="text" v-model="ruleForm.idCard" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input type="text" v-model="ruleForm.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="证书编号" prop="cerfNumber">
              <el-input type="text" v-model="ruleForm.cerfNumber" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div class="" style="text-align: center;">
            <el-button type="primary" @click="search">查询</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog  :close-on-click-modal="false"
      title="证书预览和下载"
      :visible.sync="dialogVisiblePdf"
      width="60%"
      :before-close="handleClose"
    >

      <div id="pdfDom">
        <div class="proBox">
          <ul>
            <li>{{ cerfTable.name }}</li>
            <li>{{ cerfTable.idCard }}</li>
            <li>{{ cerfTable.competitionName }}</li>
            <li>{{ cerfTable.projectAndGroups }}</li>
            <li>{{ cerfTable.award }}</li>
            <li>{{ cerfTable.approveUnit }}</li>
            <li>{{ cerfTable.approveDate }}</li>
            <li>{{ cerfTable.cerfNumber }}</li>
          </ul>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-switch
          inactive-color="#67c23a"
          v-model="downType"
          active-text="图片下载"
          inactive-text="pdf下载"
          style="margin-right: 20px;"
        >
        </el-switch>
        <el-button @click="dialogVisiblePdf = false">取 消</el-button>
        <el-button type="primary" @click="getPdf('#pdfDom')">下载</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {searchCertificate} from '@/api/search'
export default {
  data() {
    return {
      ruleForm:{
        idCard:'',
        name:'',
        cerfNumber:''
      },
      dialogVisible:false,
      cerfTable:{
        name:'姓名',
        idCard:'370283199200000000',
        competitionName:'健美操新周期',
        projectAndGroups:'组别',
        award:'等级',
        approveUnit:'颁奖单位',
        approveDate:'颁奖时间',
        cerfNumber:'202237xxxx'
      },
      dialogVisiblePdf: false,
      pageData: null, //接收html格式代码
      htmlTitle: "结业证书",
      isCanvas: false,
      downType: true // false为 pdf , true为图片
    }
  },
  methods:{
    handleClose() {
      this.dialogVisiblePdf = false;
    },
    search() {
      if(this.ruleForm.idCard == '') {
        this.$message.error('请输入身份证')
      } else if(this.ruleForm.name == '') {
        this.$message.error('请输入姓名')
      } else if(this.ruleForm.cerfNumber == '') {
        this.$message.error('请输入证书编号')
      } else {
        let params = {
          idCard:this.ruleForm.idCard,
          name:this.ruleForm.name,
          cerfNumber:this.ruleForm.cerfNumber
        }
        searchCertificate(params).then(res => {
          if(res.code == 200) {
            this.cerfTable = res.data
            this.dialogVisiblePdf =true
          }
        }).catch(err => {
          console.log(err)
        })
      }
    }
  }
}
</script>
<style scoped>
.dis-cell {
  border: 1px solid #EBEEF5;
  padding: 12px 10px;
  box-sizing: border-box;
  text-align: left;
  font-weight: 400;
  line-height: 1.5;
  font-weight: 700;
  color: #909399;
  background: #fafafa;
}
.dis-cell i {
  font-family: element-icons!important;
  /* speak: none; */
  font-style: normal;
  font-weight: 400;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  vertical-align: baseline;
  display: inline-block;
}
.dis-body {
  border: 1px solid #ebeef5;
    padding: 12px 10px;
    box-sizing: border-box;
    text-align: left;
    font-weight: 400;
    line-height: 1.5;
}

::v-deep .el-dialog__body {
  padding: 0px;
  display: flex;
  justify-content: center;
}
#pdfDom {
  /* 要想pdf周边留白，要在这里设置 */
  padding: 20px;
  width: 750px;

}
.proBox {
  background: url("@/assets/zs.jpg") no-repeat;
  background-size: cover;
  width: 500px;
  height: 700px;
  padding: 90px 94px;
  box-sizing: border-box;
  margin: 0 auto;
  position: relative;
  color: #000;
  font-family: SimSun;
}
ul li {
  list-style: none;
  position: relative;
  top: 131px;
  left: 100px;
  line-height: 45px;
}
</style>